% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/country_date.R
\name{create_idx}
\alias{create_idx}
\title{Gap Index}
\usage{
create_idx(x)
}
\arguments{
\item{x}{Vector of years or Date objects.}
}
\description{
\code{create_idx} returns a grouping index as a numeric vector
denoting sequential dates, \emph{i.e.} groups separated by year
gaps. The resulting vector can be coerced to a factor for use with
\code{split} or \code{dplyr::group_by}.
}
\details{
Where this is most useful is when we fill in missing
    observations and we want to make sure we never fill across year
    gaps. \code{create_idx} returns a grouping vector that can be
    used when splitting before filling.

    The actual values of the returned vector are inconsequential
    and are only useful for identifying groups.

    As an example, V-Dem does not code the occupation of Germany
    after WWII. To ensure that values prior to 1946 are not used to
    fill in missingness after 1949, the data should be split by
    gaps by creating an index column denoting the two groups.
}
\examples{
dates <- as.Date(c("1900-01-01", "1901-12-31", "1903-01-01"))
create_idx(dates)

years <- c(1900, 1901, 1905, 1907)
create_idx(years)

}
